<a href="javascript:void(0);" onclick="$('html, body').animate({ scrollTop:0},500);">
    <img class="return-top" src="/static/images/return-top.png">
</a>
<script type="text/javascript">
    $(window).scroll(function () {
        var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        if (scrollTop > 300) {
            $(".return-top").fadeIn();
        } else {
            $(".return-top").fadeOut();
        }
    });
</script>